package stuman.entity;

import java.io.Serializable;
import java.util.ArrayList;

import stuman.util.GPAConvert;
import android.text.Editable;

public class Subject implements Serializable{
	

	private static final long serialVersionUID = 1L;
	
	private String name;
	private double GPA, grade;
	private ArrayList<Section> sections = new ArrayList<Section>();

	
	public Subject(String n){this.name = n;}
	
	public String getName(){return name;}
	
	//set gpa for this subject
	public void setGPA(double g){this.GPA = g;}
	public void setGPA(Editable g){this.GPA = GPAConvert.convertToGPA(g);}
	
	public double getGPA(){return GPA;}
	
	public void addSection(Section s){
		sections.add(s);
	}
	
	public Section getSection(String sectionName){
		for (int i=0; i<sections.size(); i++){
			if (sections.get(i).getName().equals(sectionName)){
				return sections.get(i);
			}
		}
		
		return null;
	}
	
	public ArrayList<Section> getSections(){
		return this.sections;
	}
	
	public double getGrade(){
		grade = 0;
		for (int i = 0;i<sections.size();i++){
			grade = grade + sections.get(i).getWeightedAverage();
		}
		return grade;
	}
	
}
